package com.itfreer.gis.entity;

import java.io.Serializable;
import java.util.LinkedHashSet;
import java.util.Set;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.Id;
import javax.persistence.Index;
import javax.persistence.JoinColumn;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.springframework.beans.BeanUtils;

import com.itfreer.form.api.JdbcBaseEntity;
@Entity(name = "gis_analysis_config")
@Table(indexes = { 
        @Index(name="gac_s_medname", columnList="s_medname"),
        @Index(name="gac_layer_id", columnList="layer_id") })
public class JdbcGisAnalysisConfigEntity implements JdbcBaseEntity<GisAnalysisConfigEntity>, Serializable {

	private static final long serialVersionUID = 8956058710867750399L;
	/**
	 * 数据库主键
	 */
	@Id
	@Column(name="s_id")
	private String id;
	
	/**
	 * 元数据名称
	 */
	@Column(name="s_medname")
	private String medname;
	
	/**
	 * 元数据别名
	 */
	@Column(name="s_med_alianame")
	private String medalianame;
	
	/**
	 * 图层id
	 */
	@Column(name="layer_id")
	private String layerId;
	
	/**
	 * 可以使用的动态图层id
	 */
	@Column(name="query_layer_id")
	private Integer queryLayerId;
	/**
	 * 是否可用
	 */
	@Column(name="is_used")
	private Integer isUsed;
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getMedname() {
		return medname;
	}
	public void setMedname(String medname) {
		this.medname = medname;
	}
	
	
	public String getMedalianame() {
		return medalianame;
	}
	public void setMedalianame(String medalianame) {
		this.medalianame = medalianame;
	}
	
	public String getLayerId() {
		return layerId;
	}
	public void setLayerId(String layerId) {
		this.layerId = layerId;
	}
	public Integer getIsUsed() {
		return isUsed;
	}
	public void setIsUsed(Integer isUsed) {
		this.isUsed = isUsed;
	}
	public Integer getQueryLayerId() {
		return queryLayerId;
	}
	public void setQueryLayerId(Integer queryLayerId) {
		this.queryLayerId = queryLayerId;
	}
	
	/**
	 * 子表对象统计类别
	 */
	@SuppressWarnings("deprecation")
	@org.hibernate.annotations.ForeignKey(name = "none")
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "p_id")
	@OrderBy("s_id ASC")
	private Set<JdbcGisStatisticsCategoryEntity> statisticsCateory = new LinkedHashSet<JdbcGisStatisticsCategoryEntity>();
	

	/**
	 * 子表对象统计字段
	 */
	@SuppressWarnings("deprecation")
	@org.hibernate.annotations.ForeignKey(name = "none")
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "p_id")
	@OrderBy("s_id ASC")
	private Set<JdbcGisStatisticsFieldEntity> statisticsField = new LinkedHashSet<JdbcGisStatisticsFieldEntity>();
	
	/**
	 * 子表对象显示字段
	 */
	@SuppressWarnings("deprecation")
	@org.hibernate.annotations.ForeignKey(name = "none")
	@OneToMany(cascade = { CascadeType.ALL }, fetch = FetchType.LAZY)
	@JoinColumn(name = "p_id")
	@OrderBy("s_id ASC")
	private Set<JdbcGisAnalysisShowFieldEntity> showField = new LinkedHashSet<JdbcGisAnalysisShowFieldEntity>();
	
	
	public Set<JdbcGisStatisticsCategoryEntity> getStatisticsCateory() {
		return statisticsCateory;
	}
	public void setStatisticsCateory(Set<JdbcGisStatisticsCategoryEntity> statisticsCateory) {
		this.statisticsCateory = statisticsCateory;
	}
	public Set<JdbcGisStatisticsFieldEntity> getStatisticsField() {
		return statisticsField;
	}
	public void setStatisticsField(Set<JdbcGisStatisticsFieldEntity> statisticsField) {
		this.statisticsField = statisticsField;
	}
	
	public Set<JdbcGisAnalysisShowFieldEntity> getShowField() {
		return showField;
	}
	public void setShowField(Set<JdbcGisAnalysisShowFieldEntity> showField) {
		this.showField = showField;
	}
	@Override
	public void from(GisAnalysisConfigEntity t) {
		BeanUtils.copyProperties(t, this);
		// 统计类别-start-
		Set<JdbcGisStatisticsCategoryEntity> JdbcStatisticsCateoryList = new LinkedHashSet<JdbcGisStatisticsCategoryEntity>();
		Set<GisStatisticsCategoryEntity> statisticsCateoryList = t.getStatisticsCateory();
		if (statisticsCateoryList != null) {
			for (GisStatisticsCategoryEntity item : statisticsCateoryList) {
				JdbcGisStatisticsCategoryEntity jdbcItem = new JdbcGisStatisticsCategoryEntity();
				jdbcItem.from(item);
				JdbcStatisticsCateoryList.add(jdbcItem);
			}
		}
		this.setStatisticsCateory(JdbcStatisticsCateoryList);
		// 统计类别-end-
		
		// 统计字段-start-
		Set<JdbcGisStatisticsFieldEntity> JdbcStatisticsFieldList = new LinkedHashSet<JdbcGisStatisticsFieldEntity>();
		Set<GisStatisticsFieldEntity> statisticsFieldList = t.getStatisticsField();
		if (statisticsFieldList != null) {
			for (GisStatisticsFieldEntity item : statisticsFieldList) {
				JdbcGisStatisticsFieldEntity jdbcItem = new JdbcGisStatisticsFieldEntity();
				jdbcItem.from(item);
				JdbcStatisticsFieldList.add(jdbcItem);
			}
		}
		this.setStatisticsField(JdbcStatisticsFieldList);
		// 统计字段-end-
		
		// 显示字段-start-
		Set<JdbcGisAnalysisShowFieldEntity> JdbcShowFieldList = new LinkedHashSet<JdbcGisAnalysisShowFieldEntity>();
		Set<GisAnalysisShowFieldEntity> showFieldList = t.getShowField();
		if (showFieldList != null) {
			for (GisAnalysisShowFieldEntity item : showFieldList) {
				JdbcGisAnalysisShowFieldEntity jdbcItem = new JdbcGisAnalysisShowFieldEntity();
				jdbcItem.from(item);
				JdbcShowFieldList.add(jdbcItem);
			}
		}
		this.setShowField(JdbcShowFieldList);
		// 显示字段-end-
	}
	
	@Override
	public GisAnalysisConfigEntity toEntity() {
		GisAnalysisConfigEntity toEntity = new GisAnalysisConfigEntity();
		BeanUtils.copyProperties(this, toEntity);
		
		// 统计类别-start-
		Set<GisStatisticsCategoryEntity> statisticsCateoryList = new LinkedHashSet<GisStatisticsCategoryEntity>();
		Set<JdbcGisStatisticsCategoryEntity> JdbcStatisticsCateoryList = this.getStatisticsCateory();
		if (JdbcStatisticsCateoryList != null) {
			for (JdbcGisStatisticsCategoryEntity item : JdbcStatisticsCateoryList) {
				statisticsCateoryList.add(item.toEntity());
			}
		}
		toEntity.setStatisticsCateory(statisticsCateoryList);
		// 统计类别-end-
		
		// 统计字段-start-
		Set<GisStatisticsFieldEntity> statisticsFieldList = new LinkedHashSet<GisStatisticsFieldEntity>();
		Set<JdbcGisStatisticsFieldEntity> JdbcStatisticsFieldList = this.getStatisticsField();
		if (JdbcStatisticsFieldList != null) {
			for (JdbcGisStatisticsFieldEntity item : JdbcStatisticsFieldList) {
				statisticsFieldList.add(item.toEntity());
			}
		}
		toEntity.setStatisticsField(statisticsFieldList);
		// 统计字段-end-
		
		// 显示字段-start-
		Set<GisAnalysisShowFieldEntity> showFieldList = new LinkedHashSet<GisAnalysisShowFieldEntity>();
		Set<JdbcGisAnalysisShowFieldEntity> JdbcShowFieldList = this.getShowField();
		if (JdbcShowFieldList != null) {
			for (JdbcGisAnalysisShowFieldEntity item : JdbcShowFieldList) {
				showFieldList.add(item.toEntity());
			}
		}
		toEntity.setShowField(showFieldList);
		// 显示字段-end-
		
		return toEntity;
	}
}
